<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td><input type="text" v-model="queryinfo.HouseTypeName"/></td>
                </tr>
                <tr>
                    <td>是否有窗</td>
                    <td>
                        <input type="radio" v-model="queryinfo.IsWindow" name="State" :value="0"/>有窗
                        <input type="radio" v-model="queryinfo.IsWindow" name="State" :value="1"/>无窗
                    </td>
                </tr>
                <tr>
                    <td>房型面积</td>
                    <td><input type="text" v-model="queryinfo.Area"/></td>
                </tr>
                <tr>
                    <td>房型图片</td>
                    <td><input type="file" @change="img"/>
                        <img :src="queryinfo.Photo" alt="" width="100" height="100" v-if="queryinfo.Photo!=''"/></td>
                </tr>
                <tr>
                    <td>房型价格</td>
                    <td><input type="text" v-model="queryinfo.Price"/></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="radio" v-model="queryinfo.State" name="Stat" :value="0"/>启用
                        <input type="radio" v-model="queryinfo.State" name="Stat" :value="1"/>禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="add" class="btn btn-success"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue';
import axios from 'axios';
import moment from 'moment';
import {useRouter,useRoute}from 'vue-router'
const router=useRouter();
const route=useRoute();

let queryinfo:any=reactive({
  "HouseTypeName": "",
  "Photo": "",
  "Area": 0,
  "IsWindow": 0,
  "Price": 0,
  "State": 0,
})

const img=(e:any)=>{
    let obj=e.target.files[0];
    let f=new FormData();
    f.append('file',obj);
    axios({
        url:'/api/ImgPhoto/Imgfpr',
        method:'post',
        data:f
    })
    .then(res=>{
        console.log(res);
        queryinfo.Photo=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}


const add=()=>{
    axios({
        url:'/api/House/AddHouse',
        method:'post',
        data:queryinfo,
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert('添加成功');
            router.push('/houselist');
        }
        else{
            alert('添加失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>